# -*- coding: utf-8 -*-

import imageio
import tifffile
import numpy as np
import matplotlib.pyplot as plt
from PIL import Image


# func1
vid = imageio.get_reader('E:/2023-05-23 20-11-41.tiff')
print(f'总共{len(vid)}')

circle = 1
angle = 0
fps = 14.89     # 自定义

# func2
with tifffile.TiffFile('E:/2023-05-23 20-11-41.tiff') as tif:
    try:
        # 获取帧率
        fps = tif.shaped_metadata[0]['fps']         # 获取视频写入的帧率信息
        print(fps)
    except Exception as e:
        print(e)
    angle_per_image = 360 / fps         # 每张图片的角度间隔
    for page in tif.pages:
        frame = page.asarray()
        img = Image.fromarray(frame)        # ndarray转换为PIL类型
        new_file_name = f"{circle}-{angle}.tiff"
        angle += angle_per_image
        if angle >= 360:
            angle %= 360
            circle += 1
        # 以指定文件名格式保存图像
        filename = f'E:/2023-05-23 09-22-27/{new_file_name}'
        img.save(filename)      # 保存

